package com.itcam.iostream;

import java.io.*;

/**
 * Author:Cammy.Wu
 * Date:2024-05-13
 * Description:转换流
 */

public class TransferStreamDemo02 {
    public static void main(String[] args) throws IOException {
        // 1.创建文件
        File f1 = new File("E:\\IOstream\\Input.txt");
        // 2.目标文件
        File f2 = new File("E:\\IOstream\\OutputTransfer.txt");
        // 3.输入方向
        FileInputStream fis = new FileInputStream(f1);
        InputStreamReader isr = new InputStreamReader(fis,"utf-8");
        // 4.输出方向
        FileOutputStream fos = new FileOutputStream(f2);
        OutputStreamWriter osw = new OutputStreamWriter(fos,"gbk");
        // 5.开始动作
        char[] chars = new char[20];
        int len=isr.read(chars);
        while(len!=-1){
            System.out.print(new String(chars, 0, len));
            osw.write(chars,0,len);
            len=isr.read(chars);
        }
        // 6.关闭流
        osw.close();
        isr.close();
    }
}
